//
//  HomePagePythonView.swift
//  民生生活
//
//        320305199006173353
//        季延龙
//  Created by apple on 2017/8/8.
//  Copyright © 2017年 youjindi.app.com. All rights reserved.
//

import UIKit

class HomePagePythonView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        layout()
        getData()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func getData() -> Void {
        
    }
    
    func layout() -> Void {
        let titleF = CGRect(x: 0, y: 0, width: ScreenWidth, height: 23)
        let title = HomePageTitleView(titleF, "夏日时光")
        addSubview(title)
        
        let imageW = (ScreenWidth - 30)/2
        for index in 0..<4{
            var btnPoint = CGPoint(x: CGFloat(index) * (imageW + 10) + 10, y: 28)
            if (btnPoint.x + 100 > ScreenWidth){
                btnPoint = CGPoint(x: CGFloat(index - 2) * (imageW + 10) + 10 , y: 118)
            }
            let btnFrame = CGRect(x: btnPoint.x, y: btnPoint.y, width: imageW, height: 80)
            let btn = UIImageView(frame: btnFrame)
            btn.backgroundColor = UIColor.red
            btn.layer.cornerRadius = 3
            addSubview(btn)
            
        }
        
    }
    
    lazy var viewModel: HomePageViewModel = {
        let viewModel = HomePageViewModel()
        return viewModel
    }()

}

class HomePageTitleView: UIView {
    
    init(_ frame: CGRect,_ title: String) {
        super.init(frame: frame)
        layout(title)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func layout(_ title: String) -> Void {
        let titleL = UILabel()
        let leftLine = UIView()
        let rightLine = UIView()
        
        leftLine.backgroundColor = UIColor.red
        rightLine.backgroundColor = UIColor.red
        titleL.text = title
        titleL.textAlignment = .center
        titleL.textColor = UIColor.red
        
        addSubview(titleL)
        addSubview(leftLine)
        addSubview(rightLine)
        
        titleL.mas_makeConstraints { (m) in
            m?.centerX.equalTo()(self.mas_centerX)
            m?.top.equalTo()(self.mas_top)
            m?.width.offset()(100)
            m?.height.offset()(23)
        }
        
        leftLine.mas_makeConstraints { (m) in
            m?.right.equalTo()(titleL.mas_left)?.offset()(-8)
            m?.top.equalTo()(titleL.mas_centerY)
            m?.width.offset()(43)
            m?.height.offset()(1)
        }
        
        rightLine.mas_makeConstraints { (m) in
            m?.left.equalTo()(titleL.mas_right)?.offset()(8)
            m?.top.equalTo()(titleL.mas_centerY)
            m?.width.offset()(43)
            m?.height.offset()(1)
        }
    }
}
